<template>
  <!-- 电子文书 -->
  <view class="textVer textBooks">
    <view class="books-content">
      <view class="books-topic">
        <view>{{ detail.policeAgencyName }}</view>
        <view>责令整改通知书</view>
        <view>
          {{ detail.postShopName }}行罚决字 【{{ fullYear }}】
          {{ detail.orderNo }}号
        </view>
      </view>

      <view class="books-article">
        <view class="artTwo">
          <text class="article-con" style="color: #000000">
            {{ detail.companyName }}：
          </text>
        </view>

        <view class="artTwo">
          <text class="article-title">
            根据 《{{ detail.industryLegalBasis }}》的规定，我所于
            <text class="article-con">{{
              moment(detail.checkTime).format("YYYY")
            }}</text>年
            <text class="article-con">
              {{ moment(detail.checkTime).format("MM") }} </text>月
            <text class="article-con">
              {{ moment(detail.checkTime).format("DD") }} </text>日对你单位(场所)进行常规检查,发现你单位(场所)

            <text class="article-con" v-for="(item, index) in checkCategoryInfoList" :key="item.id">
              <block v-if="checkCategoryInfoListNum.indexOf(index) != -1">{{ item.industryExamineCategoryName }}存在下列第{{
                  sortOrderNum[index].join("、")
                }}项的违法行为，
              </block>
            </text>
            现责令改正:
          </text>
        </view>

        <view class="artTwo" v-for="item in checkCategoryInfoList" :key="item.id" style="text-indent: 0">
          <text class="article-title" style="font-weight: bold">
            {{ item.industryExamineCategoryName }}
          </text>

          <view v-for="afwe in item.checkDetailInfoList" :key="afwe.sortOrder" class="article-title"
            :class="afwe.pass == 0 ? 'colorRed' : ''">
            <image :src="
                afwe.pass == 0
                  ? baseImgUrl + 'square_icon2.png'
                  : baseImgUrl + 'square_icon.png'
              " mode="aspectFill" class="squareImg"></image>
            {{ afwe.sortOrder }}.{{ afwe.industryExamineDetailName }}
          </view>
        </view>

        <view class="artTwo">
          <text class="article-title">
            对上述检查不合格项，责令你单位(场所)于
            <text class="article-con">{{
              moment(detail.penaltyEndTime).format("YYYY")
            }}</text>年
            <text class="article-con">
              {{ moment(detail.penaltyEndTime).format("MM") }} </text>月
            <text class="article-con">
              {{ moment(detail.penaltyEndTime).format("DD") }} </text>日前改正。
          </text>
        </view>

        <view class="artTwo">
          <text class="article-title">
            改正期间，你单位(场所)应当采取措施，确保消防安全，对消防安全违法行为，将依法予以处罚。
          </text>
        </view>

        <view class="seal-person">
          <view>
            <view class="artTwo">
              <text class="article-title"> 被检查单位(场所)签收: </text>
              <view>
                <image :src="imgPrefix + detail.principalSignatureUrl" mode="aspectFill" class="prinImg"></image>
              </view>
            </view>
          </view>
          <view class="stampTime">
            <image :src="imgPrefix + detail.areaElectronicSignature" mode="aspectFill"></image>

            <view class="poView">
              <view class="poName" style="padding-bottom: 20rpx">
                派出所公章
              </view>
              <view class="poName">
                {{ formatters(detail.checkTime, "wordDay") }}
              </view>
            </view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  import {
    electronicRecords
  } from "@/api/goover.js";
  import {
    formatters,
    formattersWord
  } from "@/utils/util.js";
  import moment from "@/utils/moment.js";
  import {
    getAction
  } from "../../utils/request";

  export default {
    name: "textBooks",
    data() {
      return {
        baseImgUrl: this.$baseImgUrl,
        imgPrefix: uni.getStorageSync("imgPrefix"),
        options: {},
        fullYear: new Date().getFullYear(),
        detail: {},
        sortOrderNum: [], //  记录第几项违法行为
        checkCategoryInfoListNum: [], // 记录那些大类中有不合格项
        checkCategoryInfoList: [],
        role: uni.getStorageSync('role')
      };
    },
    onLoad(options) {
      this.options = options;
      this.getDetail(options.id);
    },
    methods: {
      formatters,
      formattersWord,
      moment,
      getDetail(id) {
        if (this.options.fronttype == 1) {
          let url = ''
          if (this.role === 'mini') {
            url = '/mini/police/check_unqualified/electronic_records'
          } else {
            url = this.role + '/inspect/electronic_records'
          }
          getAction(url, {
            unqualifiedId: id
          }).then((res) => {
            let {
              checkCategoryInfoList
            } = res.result || {};

            this.detail = res.result;
            this.checkCategoryInfoList = checkCategoryInfoList;

            let listNum = [];
            checkCategoryInfoList.forEach((item, index) => {
              this.sortOrderNum[index] = []; // 初始化
              for (var item2 in item.checkDetailInfoList) {
                if (item.checkDetailInfoList[item2].pass == 0) {
                  listNum.push(index);

                  this.sortOrderNum[index].push(
                    item.checkDetailInfoList[item2].sortOrder
                  );
                }
              }
            });

            this.checkCategoryInfoListNum = [...new Set(listNum)];
          });
        }

        // 复查不合格
        if (this.options.fronttype == 2) {
          // 检查的信息
          let url = ''
          if (this.role === 'mini') {
            url = '/mini/police/check_unqualified/electronic_records'
          } else {
            url = this.role + '/inspect/electronic_records'
          }
          getAction(url, {
            unqualifiedId: this.options.checkBookid
          }).then(
            (res) => {
              let {
                checkCategoryInfoList
              } = res.result || {};

              this.detail = res.result;
              this.checkCategoryInfoList = checkCategoryInfoList;

              let listNum = [];
              checkCategoryInfoList.forEach((item, index) => {
                this.sortOrderNum[index] = []; // 初始化
                for (var item2 in item.checkDetailInfoList) {
                  if (item.checkDetailInfoList[item2].pass == 0) {
                    listNum.push(index);

                    this.sortOrderNum[index].push(
                      item.checkDetailInfoList[item2].sortOrder
                    );
                  }
                }
              });

              this.checkCategoryInfoListNum = [...new Set(listNum)];
            }
          );
        }
      },
    },
  };
</script>

<style lang="scss" scoped>
  .textBooks {
    padding: 20rpx 0;

    .books-content {
      margin: 0 15rpx;
      min-height: 95vh;
      border: 1px solid #830707;

      .books-topic {
        color: #9e520a;
        text-align: center;
        font-weight: 500;
        line-height: 60rpx;

        view:nth-of-type(1) {
          margin-top: 20rpx;
          font-size: 28rpx;
        }

        view:nth-of-type(2) {
          font-size: 48rpx;
          font-weight: 700;
        }

        view:nth-of-type(3) {
          color: #232222;
          font-size: 24rpx;
        }
      }

      .books-article {
        margin-top: 20rpx;
        padding: 0 20rpx;
        color: #848484;
        font-size: 26rpx;
        font-weight: 500;

        .artTwo {
          text-indent: 2em;
          line-height: 60rpx;

          .article-title {
            color: #666666;
            font-size: 28rpx;

            .squareImg {
              margin-right: 10rpx;
              width: 22rpx;
              height: 22rpx;
            }
          }

          .prinImg {
            width: 205rpx;
            height: 99rpx;
          }

          .colorRed {
            color: #ee1c1c;
          }

          .article-con {
            padding-bottom: 2px;
            color: #333333;
            border-bottom: 1px solid #830707;
          }
        }

        .seal-person {
          display: flex;
          justify-content: space-between;
          position: relative;
          margin-top: 20rpx;

          .stampTime {
            min-width: 190rpx;

            image {
              width: 180rpx;
              height: 180rpx;
            }

            .poView {
              position: absolute;
              top: 20rpx;

              .poName {
                color: #000000;
                font-size: 24rpx;
                text-align: right;
              }
            }
          }
        }
      }
    }
  }
</style>